package cron

import "strings"

type funcInfoTime struct {
	Seconds string
	Minutes string
	Hours   string
	Day     string
	Month   string
	Week    string
}

type FuncInfo struct {
	time   funcInfoTime
	Set    []interface{}
	Action func()
}

func (f *FuncInfo) to(set ...interface{}) string {
	f.time = funcInfoTime{"*", "*", "*", "*", "*", "?"}
	for _, v := range set {
		v.(setFuncInfoTimeInterface).apply(&f.time)
	}
	return strings.Join([]string{f.time.Seconds, f.time.Minutes, f.time.Hours, f.time.Day, f.time.Month, f.time.Week}, " ")
}

func (f *FuncInfo) check() {

}

type setFuncInfoTimeInterface interface {
	apply(time *funcInfoTime)
}

type funcInfoTimeFunc struct {
	f func(time *funcInfoTime)
}

func (f *funcInfoTimeFunc) apply(o *funcInfoTime) {
	f.f(o)
}

func create(f func(time *funcInfoTime)) setFuncInfoTimeInterface {
	return &funcInfoTimeFunc{
		f: f,
	}
}

type setFuncInfoTime struct {
}

var SetFuncInfoTime = new(setFuncInfoTime)

func (s *setFuncInfoTime) SetSeconds(t string) interface{} {
	return create(func(time *funcInfoTime) {
		time.Seconds = t
	})
}
